#include <SFML\Graphics.hpp>
#include "World.h"

#include <vector>
#include <iostream>

using namespace sf;

World::World()
{
}
World::~World()
{
}
/*Load the sprites in memory*/
void World::init()
{
	//creates the world
	sf::Image image;
	image.create(15, 15, sf::Color(0, 255, 0));
	texture.loadFromImage(image);

	for(int i=0; i<10; i++)
	{
		for(int j=0; j<5; j++)
		{
		Sprite sprite;
		sprite.setPosition(i*20,j*20);
		sprite.setTexture(texture);
		mySprites.push_back(sprite);
		}
	}

	Sprite sprite;
		sprite.setPosition(-50,250);
		sprite.scale(30,2);
		sprite.setTexture(texture);
		mySprites.push_back(sprite);
}

void World::draw(RenderWindow& window)
{
	for(unsigned int i=0; i<mySprites.size(); i++)
	{
		window.draw(mySprites[i]);
	}
}

//returns true if the avatar collides with one of the sprites of the world
bool World::collides(sf::RectangleShape& rect)
{
	for(int i=0; i<mySprites.size(); i++)
	{
		if (mySprites[i].getGlobalBounds().intersects(rect.getGlobalBounds()))
			return true;
	}
	return false;
}
